package com.ks.config;

import com.ks.filter.GwsGatewayFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.GatewayFilterSpec;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.gateway.route.builder.UriSpec;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Function;

@Configuration
public class GatewayRoutesConfiguration {

    //注册，自定义网关过滤器
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        return builder.routes().route(r -> r
                .path("/order/**")
                .filters(f -> f.filter(new GwsGatewayFilter()))
                .uri("lb://order-service")

        ).build();
    }
}
